package org.slusk.thynwor.corestructures;

import java.awt.Color;
import java.awt.Component;

import org.slusk.thynwor.util.Coordinates;

public class Region {
	public enum RegionType {
		BASE
		, SANCTUARY
	}
	
	public final Coordinates topLeft;
	public final Coordinates bottomRight;
	public final RegionType type;
	
	public Region(Coordinates topLeft, Coordinates bottomRight, RegionType regionType) {
		this.topLeft = topLeft;
		this.bottomRight = bottomRight;
		this.type = regionType;
	}
	
	public boolean contains(Coordinates c) {
		return contains(c.x, c.y);
	}
	
	public boolean contains(int x, int y) {
		if (x >= topLeft.x 
				&& x <= bottomRight.x
				&& y >= topLeft.y
				&& y <= bottomRight.y
				) {
			return true;
		}
		return false;
	}
	
	public Coordinates getCenter() {
		int x = (topLeft.x + bottomRight.x) / 2;
		int y = (topLeft.y + bottomRight.y) / 2;
		return new Coordinates(x, y);
	}
	
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(type.toString());
		sb.append(": ");
		sb.append(topLeft.toString());
		sb.append(" - ");
		sb.append(bottomRight.toString());
		
		return sb.toString();
	}
	
	public void render(Component cell) {
		switch (type) {
		case BASE:
			cell.setBackground(new Color(225, 225, 50));
			break;
		}
	}
	
	public static void main(String args[]) {
		Coordinates tl = new Coordinates(0, 0);
		Coordinates br = new Coordinates(2, 2);
		Region a = new Region(tl, br, RegionType.BASE);

		System.out.println(a);

		System.out.println(a.contains(new Coordinates(4, 4)));

		System.out.println(a.getCenter());
	}
}
